package jxau.jwgl;

import org.springframework.boot.Banner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.http.HttpStatus;

@SpringBootApplication(scanBasePackages = "jxau.jwgl")
public class JwglApplication extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return configureApplication(application);
    }

    public static void main(String[] args) {
        // SpringApplication.run(JwglApplication.class, args);
        configureApplication(new SpringApplicationBuilder()).run(args);
        System.out.println("JwglApplication running...");
    }

    private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
        return builder.sources(JwglApplication.class).bannerMode(Banner.Mode.CONSOLE);
    }

    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        // errorPage
        container.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401"));
        container.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403"));
        container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404"));
        container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500"));
    }

}
